-- learn_engineering
-- create by zhuangsl
-- 学习工程学手册知识

return {
    apply = function(source, target, classId, value)
        -- 必须是玩家
        if source.type ~= OBJECT_TYPE_USER then
            return;
        end

        -- 可以学习的内容（不包括可以无限学的）
        local arr = EngineeringManualM.getSubjectAllCanLearn(value[1], true, true);
        -- 没得学了
        if #arr == 0 then
            -- 加个提示
            doAlert(string.format(getLocStr("learn_engineering_enough"),
                        getLocStr("engineering_manual_title_".. tostring(value[1]))));
            return;
        end

        local min = value[2];
        local max = value[3];
        if max < min then
            return;
        end

        -- 随机min ~ max级
        local rand = DungeonM.getRandSeed("learn_engineering") % (max - min + 1);
        local level = min + rand;

        -- 随机一个知识点
        rand = DungeonM.getRandSeed("learn_engineering");
        local knowledgeId = arr[rand % #arr + 1];

        -- 奖励知识点
        EngineeringManualM.rewardKnowledgePoint(knowledgeId, level);
        -- 奖励提示
        local knowledgeName = EngineeringManualM.query(knowledgeId, "name");
        doAlert(string.format(getLocStr("learn_manual_succ"), knowledgeName));
    end,
};
